package com.cungmua.app.task;

import android.content.Context;

import com.cungmua.app.handler.BaseAuthenticatedRequestHandler;
import com.cungmua.app.handler.EditProfileHandler;
import com.cungmua.app.model.request.EditProfileRequest;
import com.cungmua.app.model.response.EditProfileResponse;
import com.cungmua.app.net.CungMuaAPI;

import retrofit.RetrofitError;

/**
 * Created by kelvin.nguyen on 7/1/14.
 */
public class EditProfileTask extends AuthenticatedTask<EditProfileRequest, Void, EditProfileResponse> {
    private Context context;
    private EditProfileHandler handler;

    public EditProfileTask(Context context, EditProfileHandler handler) {
        this.context = context;
        this.handler = handler;
    }

    @Override
    protected Context getContext() {
        return context;
    }

    @Override
    protected EditProfileResponse doInBackground() throws RetrofitError {
        EditProfileRequest request = params[0];

        return CungMuaAPI.getService().editProfile(request.toFieldMap());
    }

    @Override
    protected BaseAuthenticatedRequestHandler getHandler() {
        return handler;
    }

    @Override
    protected void onSuccess(EditProfileResponse editProfileResponse) {
        handler.onEditProfile(editProfileResponse);
    }
}
